<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="2-jquery-作业/练习4：制作凡客诚品帮助中心页面/js/jquery-1.12.4.js"></script>
		<script>
		 $(function(){
			 $("#name").blur(function(){
				 var name=this;
				 //
				 
			 });
			 $("#btn").click(function(){
				 var u=$("#name");
				 let name=u[0];
				 let reg=/\d+/g;
				  
				 if(name.validity.valueMissing){
					 name.setCustomValidity("姓名不能不填！");
					 //return false;
				 }else if(name.validity.tooLong){
					 name.setCustomValidity("姓名长度在2-10个字符之间，您输入的是 "+name.value.length+"个，输入的多了");
					 //return false;
				 }else if(name.validity.tooShort){
					 name.setCustomValidity("姓名长度在2-10个字符之间，您输入的是 "+name.value.length+"个，输入的少了");
					 //return false;
				 }else if(name.validity.patternMismatch){
					 name.setCustomValidity("姓名的格式错误，必须A-Z 0-9和下划线");
					 //return false;
				 }else if(reg.test(name.value)){
					 name.setCustomValidity("姓名中不能有数字！");
					 //return false;
				 }else{
					 name.setCustomValidity("");
				 }
				 
				 //return true;
			 });
		 })
		</script>
	</head>
	<body>
		<form action="33.html" id="regForm">
			<p>
				<input autocomplete="off" id="name" type="text" name="name" placeholder="姓名" required="required" pattern="\w{2,10}">
			</p>
			<p>
				<input type="submit" id="btn" value="注册"/>
			</p>
		</form>
	</body>
</html>
